import React, { Component } from 'react';
import { Flex } from 'antd-mobile';
import * as api from '../../uitls/api'
import cun from '../../uitls/session'
import './HCsite.css'
class HCsite extends Component {
    constructor() {
        super()
        this.state = {
            dataList: [],
            user_id: ''
        }
    }
    change(num) {
        // console.log(num);
        cun.setStorage('xinxi', num)
        this.props.history.push({ pathname: '/Home/Changesite' })
    }
    add = () => {

        this.props.history.push({ pathname: '/Home/Addsite/' + 1 })
    }
    del(num) {
        let a = num.receipt_address_id
        this.axios({
            url: api.POST_DELaddress,
            method: 'post',
            params: {
                receipt_address_id: a
            }
        }).then(data => {
            console.log(data);
            this.initdata()
        })
    }
    fanhui = () => {
        this.props.history.push('/Home/MyInfo')
    }
    initdom = () => {
        console.log(1232);
        return this.state.dataList.map((item, i) => {
            return <div key={i}>
                <Flex>
                    <div style={{ width: '75%' }}>
                        <div className='HCsite_site'>
                            <div><span className='HCsite_class'>{item.receipt_label}</span>{item.receipt_address}</div>
                            <div>
                                <span>{item.receipt_people} </span>
                                <span> {item.receipt_sex}</span>
                                <span> {item.receipt_phone}</span>
                            </div>
                        </div>
                    </div>
                    <div style={{ width: '25%' }}>
                        <div className='HCsite_but'>
                            <i className='iconfont icon-shanchu' onClick={() => this.del(item)}></i>
                            <i className='iconfont icon-web-icon-' onClick={() => this.change(item)}></i>
                        </div>
                    </div>
                </Flex>
            </div>
        })
    }
    componentDidMount() {
        this.initdata()
    }
    initdata = () => {
        this.axios({
            url: api.GET_Queryaddress,
            method: 'get',
            params: {
                user_id: 1
            }
        }).then(data => {
            console.log(data.data.data);
            this.setState({
                dataList: data.data.data
            })
        })
    }
    render() {
        return (
            <div className='HCsite_box'>
                <Flex style={{ backgroundColor: '#FFD656' }} className='dingwei'>
                    <Flex.Item>
                        <div className='HCsite_title_icon'>
                            <i className="iconfont icon-jiantouarrowhead7 " onClick={this.fanhui}></i>
                        </div>
                    </Flex.Item>
                    <Flex.Item>
                        <div className="HCsite_sub-title">我的地址</div>
                    </Flex.Item>
                    <Flex.Item>
                        <div className='HCsite_add' onClick={this.add}>新增地址</div>
                    </Flex.Item>
                </Flex>
                {this.initdom()}
            </div>
        );
    }
}

export default HCsite;